<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <%@ include file="/WEB-INF/views/include/head.jsp"%>
    <link rel="stylesheet" href="${ctxStatic}/css/list.css">
    <script>
    $(document).ready(function(){
    	$("#materialTypeCd").select2();
    });
    
   //检索 
   function searchListForm() {
   	    var params = $("#searchForm").serialize();
        $.post("${ctx}/purchase/handbook/proMaterialSelect",params,function(result) {
            // 回调函数赋值
            var h = $(callBackHtml(result)).find("#listHtml").html();
            $('#listHtml').html(h);
            $("#materialTypeCd").select2();
        }, 'html');
	}
            
	 //重置
	function clean() {
    	 $("#supplierName").val('');
    	 $("#indentNo").val('');
    	 $("#materialNameCn").val('');
		 $("#materialTypeCd").val('');
		 $("#materialTypeCd").select2();
		 searchListForm();
	}    
    
    //选择按钮事件
    function selectFunction(obj){
    	// 判断是否被选中
    	var bolSelected = $(obj).hasClass("trSelected");
    	if (bolSelected) {
    		$(obj).removeClass("trSelected");
    	} else {
    		$(obj).addClass("trSelected");
    	}
    }
    
    function selectMaterial() {
    	//获取 iframe 数量 
    	var frLength = window.parent.frames.length;
    	//父画面下标 
    	var parentIndex = frLength-2;
    	var arr =  $("#listHtml").find(".trSelected").find(".none");
    	var returnValue = '';
    	if(arr!=null && arr.length>0){
    	var arrList = new Array();
	    	$.each(arr, function(i, item){
	    		arrList[i] = $(this).text();
	    	});
	    	
	    	returnValue = arrList.join(",")
    	}
    	window.parent.frames[parentIndex].selectMaterialCallBack(returnValue);
    	closeWin(); 
    }
    </script>
    
</head>
<body>
<form id="searchForm">
<c:set value="<%=ResourcesUtil.getConfig(\"material_Category\")%>" var="materialCategory" />
<div class="layerHeader clearfix" style="width: 800px">
	<p class="headerTitle"><spring:message code="handBook_material_title" /></p>
	<div class="headerButton clearfix">
                <button type="button" onclick="searchListForm();"><spring:message code="commom_check" /></button>
                <button type="button" onclick="clean();"><spring:message code="common_reset" /></button>
                <button type="button" onclick="selectMaterial()"><spring:message code="style_selectOK" /></button>
                <button type="button" onclick="closeWin();"><spring:message code="btn_cancle" /></button>
    </div>
</div>
<div class="listArea" style="width: 800px">
	<div class="listBg">
	    <div class="searchArea clearfix">
            <div class=" clearfix">
                <!-- 供货商名称 -->
                <div class="searchInp clearfix">
                    <p><spring:message code="handBook_material_search_supplie" /></p>
                    <input type="text" id="supplierName" name="supplierName">
                </div>
                <!-- 原辅料类别 -->
                <div class="searchInp clearfix">
                    <p><spring:message code="handBook_material_search_material_category" /></p>
                    <select class="width-125px" id="materialTypeCd" name="materialTypeCd">
                        <option value=""><spring:message code="material_pleaseChoosed"/></option>
                     <c:forEach items="${fns:getDictList(materialCategory)}"   var="category">
                         <option  <c:if test="${fn:split(handBook.materialTypeCd,'-')[1] eq category.itemValue}">selected="selected"</c:if> value="${category.itemCode}-${category.itemValue}" > 
                             ${category.itemName}
                         </option>
                     </c:forEach>
                    </select>
                </div>                
                <!-- 合同订单号 -->
                <div class="searchInp clearfix">
                    <p><spring:message code="handBook_material_search_indent_no" /></p>
                    <input type="text" id="indentNo" name="indentNo">
                </div>
                <!-- 面辅料名称 -->
                <div class="searchInp clearfix items">
                    <p><spring:message code="handBook_material_search_material_name" /></p>
                    <input type="text" id="materialNameCn" name="materialNameCn" style="width:128px">
                </div>
            </div>
        </div>
	
        <div class="tableArea tabBoxSm" id="listHtml">
        <input type="hidden" id="commaIndentId" name="commaIndentId" value="${handBook.commaIndentId}"/>
            <div class="tableScroll tabSm" style="overflow: auto;height: 317px;width:760px;">
                <table cellpadding="0" class="tableHead " >
                    <thead>
                    <tr>
                        <th><p class="table-No"><spring:message code="handBook_material_list_no" /></p></th>
                        <th><p style="width:70px;"><spring:message code="handBook_material_list_img" /></p></th>
                        <th><p style="width:70px;"><spring:message code="handBook_material_list_name" /></p></th>
                        <th><p style="width:60px;"><spring:message code="handBook_material_list_color" /></p></th>
                        <th><p style="width:60px;"><spring:message code="handBook_material_list_compositio" /></p></th>
                        <th><p style="width:60px;"><spring:message code="handBook_material_list_spec" /></p></th>
                        <th><p style="width:50px;"><spring:message code="handBook_material_list_unit" /></p></th>
                        <th><p style="width:50px;"><spring:message code="handBook_material_list_supplie" /></p></th>
                        <th><p style="width:80px;"><spring:message code="handBook_material_list_indent_no" /></p></th>
                        <th><p style="width:60px;"><spring:message code="handBook_material_list_style_no" /></p></th>
                        <th><p style="width:60px;"><spring:message code="handBook_material_list_material_num" /></p></th>
                        <th><p style="width:60px;"><spring:message code="handBook_material_list_reality_quantity" /></p></th>
                    </tr>
                    </thead>
                </table>
                <table cellpadding="0" class="tableBody" >       
                <c:if test="${not empty handBook.materialSelectList}">       
                    <tbody>
                    <c:forEach items="${handBook.materialSelectList}" var="materialSelect" varStatus="status">
                    <tr onclick="selectFunction(this)">
                        <td><p class="table-No">${status.index+1}</p></th>
                        <!-- 物料图片 -->
                        <td><p style="width:70px;">
                          <c:if test="${not empty materialSelect.materialFile}">
                              <img src='${materialSelect.materialFile}'>
                          </c:if>
                          <c:if test="${empty materialSelect.materialFile}">
                              <img src='${ctxStatic}/images/pic-none.jpg'>
                          </c:if>
                        </p></td>
                        <!-- 名称编码 -->
                        <td><p style="width:70px;" class='text_overflow' data-toggle='tooltip' title='${materialSelect.materialNameCn}<br>${materialSelect.materialCode}'>${materialSelect.materialNameCn}<br>${materialSelect.materialCode}</p></td>
                        <!-- 物料颜色 -->
                        <td><p style="width:60px;">${materialSelect.materialColor}</p></td>
                        <!-- 物料成分 -->
                        <td><p style="width:60px;">${materialSelect.materialComposition}</p></td>
                        <!-- 幅宽 -->
                        <td><p style="width:60px;">${materialSelect.materialSpec}</p></td>
                        <!-- 单位 -->
                        <td><p style="width:50px;">${fns:getDictName(materialSelect.unitCd)}</p></td>
                        <!-- 供货商 -->
                        <td><p style="width:50px;" class='text_overflow' data-toggle='tooltip' title='${materialSelect.supplierName}'>${materialSelect.supplierName}</p></td>
                        <!-- 合同订单号 -->
                        <td><p style="width:80px;" class='text_overflow' data-toggle='tooltip' title='${materialSelect.indentNo}'>${materialSelect.indentNo}</p></td>
                        <!-- 款号 -->
                        <td><p style="width:60px;"  class='text_overflow' data-toggle='tooltip' title='${materialSelect.styleCustomerNo}'>${materialSelect.styleCustomerNo}</p></td>
                        <!-- 预订耗料 -->
                        <td><p style="width:60px;"><fmt:formatNumber value="${materialSelect.materialReserveQuantity}" pattern="#,##0.####"/></p></td>
                        <!-- 已定数量 -->
                        <td><p style="width:60px;"><fmt:formatNumber value="${materialSelect.materialRealityQuantity}" pattern="#,##0.####"/></p></td>
                        <!-- 核料明细id -->
                        <td class="none">${materialSelect.materialReservePurchaseId}</td>
                      </tr>  
                      </c:forEach>
                    </tbody>
                </c:if>    
                </table>
            </div>
        </div>
    </div>
</div>
</form>
</body>
</html>